import Title from 'antd/lib/typography/Title'
import React, { useEffect } from 'react'
import { CartItem } from '../../helpers/cart'
export interface Props {
  cart: CartItem[],
  setTotalPrice: (totalPrice: number) => void
}
const TotalPrice = (props:Props) => {
  const {cart, setTotalPrice} = props
  const getTotalPrice = ()=> {
    return cart.reduce((currentValue, nextValue)=>{
    return currentValue += nextValue.count*nextValue.price
  },0)
}
  useEffect(()=>{
    setTotalPrice(getTotalPrice())
  },[cart])
  return (
    <div>
      <Title level={4}>商品总价{getTotalPrice()}</Title>
    </div>
  )
}
export default TotalPrice